﻿//"proczo.sc","Procedury zamówienia obcego","\Procedury\",0,1.0.0,SYSTEM

#include "MobileWarehouse - include"

int Sub OnAddNewDokument(long lId)
	int block = IsLocked(lId, 5)
	if(block == 0) then
		Lock(lId, 5)
	endif
	OnAddNewDokument = 0
EndSub

int Sub OnBeforeInsert(long lId)
	OnBeforeInsert = 0
EndSub

int Sub OnAfterInsert(long lId)
	Unlock(lId, 5)
	OnAfterInsert = 0
EndSub

int Sub OnKhChanged(long lId)
	OnKhChanged = 0
EndSub

int Sub OnBeforeEdit(long lId)
	int canEditFromOperation = CheckDocumentInOperation(lId, 3)
	int confirmEdit = 0
	if(canEditFromOperation != 0) then				
		confirmEdit = CannotEditDocumentInOperation()
	endif	
	
	int block = 0
	if(confirmEdit != 0) then				
		OnBeforeEdit = confirmEdit
	else	
		block = IsLocked(lId, 5)
		if(block == 0) then
			Lock(lId, 5)
			OnBeforeEdit = 0
		else
			OnBeforeEdit = DocumentInEditMode()
		endif
	endif
	//OnBeforeEdit = 0
EndSub

int Sub OnBeforeBuforEdit(long lId)
	int canEditFromOperation = CheckDocumentInOperation(lId, 3)
	int confirmEdit = 0
	if(canEditFromOperation != 0) then				
		confirmEdit = CannotEditDocumentInOperation()
	endif	
	
	if(confirmEdit != 0) then				
		OnBeforeBuforEdit = confirmEdit
	else	
		OnBeforeBuforEdit = 0
	endif
EndSub

int Sub OnAfterUpdate(long lId)
	Unlock(lId, 5)
	OnAfterUpdate = 0
EndSub

int Sub OnAfterBuforUpdate(long lId)
	Unlock(lId, 5)
	OnAfterBuforUpdate = 0
EndSub

int Sub OnBeforeDelete(long lId)
	int canDeleteFromOperation = CheckDocumentInOperation(lId, 3)
	int confirmDelete = 0
	if(canDeleteFromOperation != 0) then				
		confirmDelete = CannotDeleteDocument()
	endif	
	
	if(confirmDelete != 0) then				
		OnBeforeDelete = confirmDelete
	else
		Unlock(lId, 5)
		OnBeforeDelete = 0
	endif		
EndSub

int Sub OnBeforeBuforDelete(long lId)
	int canDeleteFromOperation = CheckDocumentInOperation(lId, 3)
	int confirmDelete = 0
	if(canDeleteFromOperation != 0) then				
		confirmDelete = CannotDeleteDocument()
	endif	
	
	if(confirmDelete != 0) then				
		OnBeforeBuforDelete = confirmDelete
	else
		Unlock(lId, 5)
		OnBeforeBuforDelete = 0
	endif
EndSub

int Sub OnAfterDelete(long lId)
	Unlock(lId, 5)
	OnAfterDelete = 0
EndSub

int Sub OnAfterBuforDelete(long lId)
	Unlock(lId, 5)
	OnAfterBuforDelete = 0
EndSub

int Sub OnBeforeAnuluj(long lId)
	int canCancelFromOperation = CheckDocumentInOperation(lId, 3)
	int confirmCancel = 0
	if(canCancelFromOperation != 0) then				
		confirmCancel = CannotDeleteDocument()
	endif	
	
	if(confirmCancel != 0) then				
		OnBeforeAnuluj = confirmCancel
	else
		Unlock(lId, 5)
		OnBeforeAnuluj = 0
	endif	
EndSub

int Sub OnTwChanged(long lId)
	OnTwChanged = 0
EndSub

int Sub OnBeforeCancel(long lId)
	OnBeforeCancel = 0
EndSub

int Sub OnAfterCancel(long lId)
	Unlock(lId, 5)
	OnAfterCancel = 0
EndSub